package cn.zyq.ykb.system.aspect;

import cn.zyq.ykb.system.common.BackParam;
import cn.zyq.ykb.system.enums.core.ResponseCodeEnum;
import cn.zyq.ykb.system.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class ControllerAspect {
    // @Pointcut("execution(public * cn.zyq.ykb.controller.mgt..*(..))"
    //         + " || execution(public * cn.zyq.ykb.controller.h5..*(..))")
    // private void controllerAspect() {
    // }

    @Pointcut("execution(public * cn.zyq.ykb.controller..*(..))"
            + " && !execution(public * cn.zyq.ykb.controller.mgt.login..*(..))"
            + " && !execution(public * cn.zyq.ykb.controller.h5.game..*(..))"
            + " && !execution(public * cn.zyq.ykb.controller.file..*(..))"
    )
    private void controllerAspect() {
    }
//    execution(public * cn.zyq.ykb.controller.h5.pay.PayOrderController.gameIOSNotify())"
//            + " && !execution(public * cn.zyq.ykb.controller.h5.pay.PayOrderController.gameNotify())"
//                + " && !execution(public * cn.zyq.ykb.controller.h5.pay.gameAndroidNotify*(..))"
//                + " && !execution(public * cn.zyq.ykb.controller.h5.pay.gameIOSNotify*(..))"
    //            + " && !execution(public * cn.zyq.ykb.controller.wx..*(..))"



    @Around(value = "controllerAspect()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        Object result = pjp.proceed();
        if (result == null) {
            throw new BusinessException(ResponseCodeEnum.SUCCESS);
        }
        BackParam backParam = new BackParam();
        backParam.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        backParam.setCode(ResponseCodeEnum.SUCCESS.getCode());
        backParam.setData(result);
        return backParam;
    }
}
